package com.gingko.duominuo.viewmodel

import androidx.hilt.Assisted
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import com.gingko.duominuo.data.Resource
import com.gingko.duominuo.data.asResource
import com.gingko.duominuo.data.isSuccess
import com.gingko.duominuo.data.model.*
import com.gingko.duominuo.data.request.*
import com.gingko.duominuo.data.source.repository.GinkgoRepository
import com.gingko.duominuo.utils.getTimeSpan
import com.gingko.duominuo.utils.md5
import com.gingko.duominuo.utils.string2Millis
import com.gingkor.common.ext.toJson
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import java.util.*
import java.util.concurrent.TimeUnit

class UserViewModel @ViewModelInject constructor(
    private val ginkgoRepository: GinkgoRepository,
    @Assisted
    val state: SavedStateHandle
) : BaseViewModel() {
    private val _userInfoLiveData = MutableLiveData<UserVo?>()
    val userInfoLiveData: LiveData<UserVo?> = _userInfoLiveData

    fun getUserInfoFromDb() {
        launchOnUI(
            task = {
                _userInfoLiveData.value = ginkgoRepository.getUserInfoFromDb()
            }, isShowLoading = false
        )
    }
}
